package com.hk.modules.circuit.controller;

import com.hk.common.utils.ResponseUtils;
import com.hk.modules.circuit.service.CircuitService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;

@Slf4j
@Controller
@RequestMapping("/file")
public class UploadController {

    @Autowired
    private CircuitService circuitService;

    @ResponseBody
    @PostMapping(value="/upload")
    public ResponseEntity<Object> uploadFile(@RequestParam("file") MultipartFile file) throws Exception{

        return ResponseUtils.tryReturn("导入失败",()->{
            circuitService.uploadFile(file);
            return "上传成功";
        });
    }

}
